home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14076 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  45 lines

  1. Path: spiff.cc.iastate.edu!graphix
  2. From: graphix@iastate.edu (Kent A Vander Velden)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Derivation and calling virtual functions
  5. Date: 28 Mar 96 23:30:07 GMT
  6. Organization: Iowa State University, Ames, Iowa
  7. Message-ID: <graphix.828055807@spiff.cc.iastate.edu>
  8. References: <graphix.828032689@spiff.cc.iastate.edu>
  9. NNTP-Posting-Host: spiff.cc.iastate.edu
  10.  
  11.   This is a rewrite of my original post with corrections...
  12.  
  13.   Say we have the following:
  14.  
  15. class Base {
  16. public:
  17.   virtual void func() { // some stuff }
  18.   virtual void write() { func(); }
  19. };
  20.  
  21. class Derived : public Base {
  22. public:
  23.   void func() { // some stuff }
  24.   void write() { Base::write(); }
  25. };
  26.  
  27. Derived inst;
  28.  
  29.   Now, when I call inst.write(), Base::write() is called which in
  30. turn calls Base::func().  Is there a way to instead have Base::write()
  31. call Derived::func() if Base::write() is called from any function
  32. defined in the Derived class or specificly Derived::write()?  I hoped
  33. the virtual keyword would help in this case.
  34.  
  35.   Thanks.
  36.  
  37. >-- 
  38. >Kent Vander Velden
  39. >graphix@iastate.edu
  40.  
  41. -- 
  42. Kent Vander Velden
  43. graphix@iastate.edu
  44.  
  45.